import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/4 22:37
 * @description 创建虚拟节点
 */
public class Solution {
    public static void main(String[] args) {

    }
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode dummy = new ListNode(0);
        dummy.next = list1;
        ListNode cur = dummy;
        // 走到下标a的前一个
        for (int i = 0; i < a; i++) {
            cur = cur.next;
        }
        ListNode pre = cur;
        cur = cur.next;
        // 走到下标b的后一个
        for (int i = 0; i < b - a; i++) {
            cur = cur.next;
        }
        ListNode suf = cur.next;
        pre.next = list2;
        ListNode temp = list2;
        while (temp.next != null) {
            temp = temp.next;
        }
        temp.next = suf;
        return dummy.next;
    }
}
